<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 9.4.6 (461470)"/><meta name="author" content="704206198@qq.com"/><meta name="created" content="2017-10-16 04:10:22 +0000"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2021-07-28 07:51:09 +0000"/><title>DAY06：数组</title></head><body><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">第一节：精讲</span></span></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">1.数组的概念及定义</span></span></div><div style="box-sizing: border-box; padding: 8px; font-size: 12px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    可以存放一组数据；</span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    当需要操作多个数据时</span></span></div></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">2.数组的创建方式</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><font face="Courier New" style="font-size: 14px;"><span style="font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    var arr1 = [1,2,3];</span><span style="font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    </span><span style="font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    </span><span style="font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">   //字面量方式</span></font></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    var arr2 = new Array(1,2,3)</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">   //构造函数方式</span></font></div><div><font face="Courier New" style="font-size: 14px;"><br/></font></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">   </span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(255, 38, 0); font-family: &quot;Courier New&quot;;">注意：当只有一个数据时，两种创建方式的不同。</span></div><div><font face="Courier New" style="font-size: 14px;"><br/></font></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(255, 38, 0);">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(255, 38, 0);">var arr1 = [5]</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(255, 38, 0);">             //表示有一个数组元素5</span></font></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(255, 38, 0);">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(255, 38, 0);">var arr2 = new Array(5)</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(255, 38, 0);">    //表示有5个数组元素，值全部为</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(255, 38, 0);">undefined</span></font></div></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">3.数组的操作（push／pop／unshift／shift）</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    数组中的项，可以放任何数据，如</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    var arr = [1,"1",function(){console.log(1)},console.log(1),Math.danmom(‘’),1+1,[1,2,3],[0]]</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    数组的增、删、改、查</span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    var arr = [1,2,3];</span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    arr.push("hello")       //在数组的末尾添加元素</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    arr.unshift("first")    //在数组的开始添加元素</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    arr.pop()            //删除最后一位元素</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    arr.shift()          //删除第一个元素</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    arr.splice(n,m,a......)    //从第n个项目开始删除，一共删除m个;a可选，表示在删除的位置添加新元素a</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    arr.slice(n,m)       //返回一个新数组，从下标n的位置取到下标m位置的前一个（不包含m），可以实现截取的功能</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    arr.sort(fn)         //对数组进行排序,fn为一个函数，可选；</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">                         //当数组内的元素为字符型数字，默认排序已经无法满足，需要手动处理;</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">  </span><span style="background-color: rgb(251, 250, 248); font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">                      //如function fn(n,m){return n-m}</span></span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    注意：每个方法的返回值</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    注意：每个方法是否会修改原数组</span></span></span></span></span></div><div><span style="font-size: 14px; font-family: &quot;Courier New&quot;;">   </span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">注意：看参数</span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    注意：查文档</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><font style="font-size: 14px;" face="Courier New"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    推荐文档：</span></font></span><a href="https://blog.csdn.net/weixin_41636483/article/details/112981447" style="font-family: &quot;Courier New&quot;;">https://blog.csdn.net/weixin_41636483/article/details/112981447</a></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span></span></span></span></span></div><div style="font-size: 12px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    <img src="DAY06%EF%BC%9A%E6%95%B0%E7%BB%84.resources/128897C0-6967-4443-880F-1C416B084C21.png" height="493" width="809"/><br/></span></span></div><div style="font-size: 12px;"><div><br/></div></div><div style="font-size: 12px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    自定义功能：自定义完成</span></span></div></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">4.数组的遍历(获取数组中的每个元素)</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div style="font-size: 12px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    数组元素的获取：</span></span></div><div style="font-size: 12px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">       索引，数组元素的下标，表示数组元素在数组中的顺序，从0开始，到arr.length-1</span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    利用循环，配合索引</span></span></span></div></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">5.整数数组／字符串数组／对象数组／二维数组</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    整数数组：arr = [1,2,3,4,5,6,7]</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        数组的元素为整数</span></span></span></div><div><font face="Courier New" style="font-size: 14px;"><br/></font></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    字符串数组：arr = ["h","e","l","l","o”]</span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        数组的元素为字符串</span></span></span></span></div><div><font face="Courier New" style="font-size: 14px;"><br/></font></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    二维数组：arr = [[1,"a",3],["hello",6,8],["color","width"]]</span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        数组的元素为数组</span></span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">        如何获取而为数组内的元素：arr[2][1];      //width</span></font></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248);"><br/></span></font></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    json对象数组：arr = [{name:"Lisa"},{name:"Jack"},{name:"Loss"}]</span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        数组的元素为对象</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        如何获取对象数组内的元素：arr[1].name;    //Jack</span></span></span></div><div style="font-size: 12px;"><br/></div></div><div><span style="font-size: 18px;"><br/></span></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">6.JSON表示对象的方法</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">JSON本身是字符型数据，格式如：</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">数组和对象的组合</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    var json = [</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        {</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">            name:"LY",</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">            chinese:99,</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">            math:88</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        },</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        {</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">            name:"LY",</span></div><div><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    chinese:99,</span></div><div><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    math:88</span></div><div><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">}</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    ]</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    国际通用语言：英语</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    中国通用语言：普通话</span></div><div><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    计算机语言中的通用数据：JSON，是计算机</span><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">各种语言之间数据沟通的桥梁</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span></div><div><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(255, 38, 0); font-family: &quot;Courier New&quot;;">    在javascript中，JSON称为数组对象</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    别的语言想要对外沟通的时候称为JSON</span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    小提示：在JSON文件中，不允许出现undefined和function和NaN</span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    在强制转换过程中会省略undefined和function的属性，将NaN转成null</span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><a href="https://blog.csdn.net/weixin_41636483/article/details/112589241" style="font-family: &quot;Courier New&quot;;">https://blog.csdn.net/weixin_41636483/article/details/112589241</a></div></div><div><br/></div><div><span style="font-family: &quot;Courier New&quot;;">范围随机数</span></div><div><br/></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">第二节：应用</span></span></div><div><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">1.</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">定义一个30项的数组，数组的每一项要求都是6，每间隔5个数字，求出这五个数的平均值</span></div><div><br/></div><div><font style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">2.通过循环制造一个5 x 5的二维数组，这个数组中的数据是hello，试编程</span></font></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><span style="min-height: 17pt; font-size: 14px; color: rgb(8, 8, 8); font-family: &quot;Courier New&quot;;">    Math.round( Math.random() </span><span style="min-height: 17pt; font-size: 14px; color: rgb(87, 121, 9); font-family: &quot;Courier New&quot;;">* </span><span style="min-height: 17pt; font-size: 14px; color: rgb(8, 8, 8); font-family: &quot;Courier New&quot;;">(max</span><span style="min-height: 17pt; font-size: 14px; color: rgb(87, 121, 9); font-family: &quot;Courier New&quot;;">-</span><span style="min-height: 17pt; font-size: 14px; color: rgb(8, 8, 8); font-family: &quot;Courier New&quot;;">min)</span> <span style="min-height: 17pt; font-size: 14px; color: rgb(87, 121, 9); font-family: &quot;Courier New&quot;;">+</span> <span style="min-height: 17pt; font-size: 14px; color: rgb(8, 8, 8); font-family: &quot;Courier New&quot;;">min )</span></div><div><br/></div><div><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">3.编写生成4个数字的随机验证码的函数，</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">并生成10次，同时将结果存入数组</span></div><div><br/></div><div><br/></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">第三节：精讲</span></span></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">1.for-in循环</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    在使用for遍历数组的过程中，需要至少确定数组的长度，以判断遍历的次数</span></span></span></span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    新的遍历方式：for-in循环</span></span></span></span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot;;">   </span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(255, 38, 0); font-family: &quot;Courier New&quot;;">注意：for-in循环一般用来遍历非数组对象</span></div><div><br/></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(255, 38, 0);">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(0, 0, 0);">for-in循环中的代码每执行一次，就会对数组的元素或者对象的属性进行一次操作。我们也称这种循环为“枚举”。</span></font></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(0, 0, 0);">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(0, 0, 0);">var obj = {</span></font></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        name:"lz",</span></span></span></span></span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    age:36</span></font></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">}</span></font></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    for(var i in obj){</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        console.log(obj[i]);</span></span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    }</span></span></span></span></span></div><div><br/></div></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">2.数组的排序（冒泡／选择）</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    冒泡排序：</span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">   </span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(255, 38, 0); font-family: &quot;Courier New&quot;;">依次对数组中相邻数字进行比较(两两比较)，大的放后面</span></div><div><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;"> </span><font style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">       </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;;"><img src="DAY06%EF%BC%9A%E6%95%B0%E7%BB%84.resources/QQ%E5%9B%BE%E7%89%8720160518084652.gif" height="580" width="580"/><br/></span></font></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">[</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">5</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">99</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">2</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">9</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">5</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">67</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">7</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">10</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">23</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">]      //定义一个杂乱的数组</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    for</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">(</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">i</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">0</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;i</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">&lt;</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr.length</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">-</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;i</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">++</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">){         //大循环，用于遍历数组每个元素</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        for</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">(</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">0</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">&lt;</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr.length-i</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">-</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">++</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">){   //小循环，用于将数组中的某个元素与其它所有元素相比较</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">            var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">sum;                         //声明一个局部变量，当作第三个空瓶子</span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(105, 137, 6);">            if</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6);">(arr[j]</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(105, 137, 6);">&gt;</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6);">arr[j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(105, 137, 6);">+</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(173, 66, 239);">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6);">]){             //判断当前元素和后一个元素的大小，如果当前元素比后一个元素大</span></font></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">                sum</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr[j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">+</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">];              //将后一个元素（小元素）放在空瓶子里</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">                arr[j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">+</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">]</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr[j];           //将当前元素（大元素）放在后一个元素的位置</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">                arr[j]</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">sum;                //将小元素从空瓶子中拿出来，放在当前元素的位置</span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">            }</span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        } </span></span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    }</span></span></span></span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(74, 138, 1); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    console</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">.log(arr);                        //完成循环之后，初始数组的顺序已经发生改变</span></font></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    </span></font></div><div><br/></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    选择排序：</span></font></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;;">   </span><span style="background-color: rgb(251, 250, 248); font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(255, 38, 0); font-family: &quot;Courier New&quot;;">将第一位依次与后面的元素相比较，得到最小值，与第一位交换。再用第二位依次与后面元素相比较，得到最小值，与第二位交换。</span></span></span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    从原始数据中找到最小元素，并放在数组的最前面。然后再从下面的元素中找到最小元素，放在之前最小元素的后面，直到排序完成。</span></font></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">  </span></span><span style="font-family: &quot;Courier New&quot;;" /><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">     <img src="DAY06%EF%BC%9A%E6%95%B0%E7%BB%84.resources/%E9%80%89%E6%8B%A9%E6%8E%92%E5%BA%8F.jpg" height="268" width="375"/><br/></span></div><div style="font-size: 12px;"><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    </span></font></div></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">    var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">arr</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">[</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">5</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">99</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">2</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">9</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">5</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">67</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">7</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">10</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">,</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">23</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-variant-caps: normal; font-variant-ligatures: normal;">]</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    for</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">(</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">i</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">0</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;i</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">&lt;</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr.length</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">-</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;i</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">++</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">){      </span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(165, 178, 185); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//大循环，需要比对的次数</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">min</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr[i];                  </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(165, 178, 185); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//假定一个最小值</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">minIndex</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">i;                  </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(165, 178, 185); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//假定最小值的索引</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        for</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">(</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">var</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">i</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">+</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">1</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">&lt;</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr.length;j</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">++</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">){   </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(165, 178, 185); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//小循环，每次需要比对的次数</span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(105, 137, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">            if</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">(min</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(105, 137, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">&gt;</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr[j]){                </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(165, 178, 185); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//判断最小值是否为真的最小值</span></font></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">                min</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr[j];             </span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(165, 178, 185); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//获取真正的最小值</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">                minIndex</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">j;              </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(165, 178, 185); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//获取真正最小值的索引</span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">            }</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        }</span></span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        arr[minIndex]</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">arr[i];            </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(165, 178, 185); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//将当前元素放在最小值的位置</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        arr[i]</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span><span style="font-family: &quot;Courier New&quot;;" /><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">min;                      </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(165, 178, 185); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//将最小值放在当前元素的位置</span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    }</span></span></span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(74, 138, 1); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    console</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">.log(arr);                      </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(165, 178, 185); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">//输入排序好的数组</span></font></div></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">3.栈和堆及索引思维</span></span></div><div style="box-sizing: border-box; padding: 8px; font-size: 12px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    每个内存单元中分为两个部分，栈和堆</span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    栈在内存的最底部，类似于一个标记，名字，分类；稳定，不可更改</span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    堆数据，表示一组数据，可变更，数据量大，和栈一一对应</span></span></div><div><br style="font-size: 12px;"/></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    多个栈可以对应一个堆，反之不行</span></span></div><div><br style="font-size: 12px;"/></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    变量的声明，变量名存在了栈中</span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="font-size: 14px; background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    变量的赋值，数据存在了堆中</span></span></div><div><br/></div></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">4.值传递和引用传递</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><font style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    值传递：复制的是变量的值</span></font></div><div><font style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    引用传递：复制的是指针的指向（传递的是对象在堆内存中的内存地址）</span></font></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    如下：</span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    var</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">a</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">10</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    var</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">b</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">a;</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    var</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">b</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">20</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;</span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(74, 138, 1); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    console</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">.log(a,b);</span></font></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    var</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">a</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">= new</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">Object();</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    a.name </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">10</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    var</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">b</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">a;</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    b.name </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(173, 66, 239); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">20</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;</span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(74, 138, 1); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    console</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">.log(a.name,b.name</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">)</span></font></div><div><br/></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    再比如：</span></font></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;;">    var</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;;">a</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;;">{</span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        name</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(79, 93, 102); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">:</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(40, 156, 151); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">"张三"</span></font></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    }</span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    var</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">b</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">{</span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        name</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(79, 93, 102); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">:"</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(40, 156, 151); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">李四"</span></font></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    }</span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    function</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(228, 139, 0); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">change</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">(</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(181, 138, 0); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">obj</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">){</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        obj.name </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(40, 156, 151); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">"老张"</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">;</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        obj</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">b;</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">        return</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">obj;</span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    }</span></span></div><div><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(70, 99, 204); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    var</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">newName</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(105, 137, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">=</span> <span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(6, 6, 6); font-family: &quot;Courier New&quot;; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">change(a);</span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(74, 138, 1); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    console</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">.log(newName.name);</span></font></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(74, 138, 1); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">    console</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(6, 6, 6); font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal;">.log(a.name);</span></font></div><div><br/></div></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">5.对象的本质和意义</span></span></div><div style="box-sizing: border-box; padding: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);"><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">常规对象：</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    var obj = {</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        name:"lz",</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        age:36,</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        skill:function(){</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">            console.log(1)</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        }</span></span></span></div><div><font face="Courier New" style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">}</span></font></div><div><br/></div><div><font style="font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    </span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(255, 38, 0); font-family: &quot;Courier New&quot;;">对象的本质就是key和value</span><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">，如下</span></font></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        obj的key为name / age</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        obj的value为"lz" / 36</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    key和value一一对应</span></span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">对象都是由函数产生的</span></span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    方法(Function)，数组(Array)，对象(Object)都是对象</span></span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    上面的常规对象其实等价于：</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    var obj = new Object();</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    obj.name = "lz";</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    obj.age = 36</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    obj.skill = function(){</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">        console.log(1);</span></span></span></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    }</span></span></span></div><div><br/></div><div><span style="font-size: 14px; background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">外面的变量对应对象身上的属性</span></span></div><div><span style="font-size: 14px; background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">外面的函数对应对象身上的方法</span></span></div><div><br/></div><div><span style="background-color: rgb(251, 250, 248);"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(51, 51, 51); font-family: &quot;Courier New&quot;;">    由此可见</span><span style="background-color: rgb(251, 250, 248); font-size: 14px;"><span style="background-color: rgb(251, 250, 248); font-size: 14px; color: rgb(255, 0, 0); font-family: &quot;Courier New&quot;;">对象的意义就是不仅可用来方便的存储数据，还可以用来编程</span></span></span></div></div><div><br/></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">1.数组的冒泡排序</span></span></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">2.数组的选择排序</span></span></div><div><br/></div><div><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">3.编写函数</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">map(arr)</span> <span style="font-size: 18px; font-family: &quot;Courier New&quot;;">把数组中的每一位数字都增加</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">30%</span></div><div><br/></div><div><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">4.编写函数</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">has(arr , 60)</span> <span style="font-size: 18px; font-family: &quot;Courier New&quot;;">判断数组中是否存在</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">60</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">这个元素，返回布尔类型</span></div><div><br/></div><div><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">5.编写函数</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">norepeat(arr)</span> <span style="font-size: 18px; font-family: &quot;Courier New&quot;;">将数组的重复元素去掉，并返回新的数组</span></div><div><br/></div><div><span style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">6.有一个从小到大排好序的数组。现输入一个数，要求按原来的规律将它插入数组中。</span></span></div><div><br/></div><div><font style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">7.</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">创建一个对象，该对象存储一个学生的信息，该对象包含学号、身份证、年龄、性别、所学专业等属性信息，同时该对象包含一个自我介绍的方法，用来输出该对象的所有信息</span></font></div><div><br/></div><div><font style="font-size: 18px;"><span style="font-size: 18px; font-family: &quot;Courier New&quot;; font-weight: bold;">扩展案例：</span><span style="font-size: 18px; font-family: &quot;Courier New&quot;;">以下是某班级一次考试的成绩表。请计算每个学生总成绩，并按总成绩排名。统计各单科成绩第一名，输出其成绩与学号。</span></font></div><div><span style="font-family: &quot;Courier New&quot;;"><img src="DAY06%EF%BC%9A%E6%95%B0%E7%BB%84.resources/835ED2F8-8678-4F93-81B9-A24174F7710D.png" height="313" width="812"/><br/></span></div><div><br/></div><div><br/></div><div><br/></div><div><br/></div><div><a href="DAY06%EF%BC%9A%E6%95%B0%E7%BB%84.resources/%E5%AD%A6%E7%94%9F%E6%88%90%E7%BB%A9%E6%8E%92%E5%BA%8F.html">学生成绩排序.html</a></div><div><br/></div><div><br/></div><div><br/></div><div><br/></div><div><br/></div><div><br/></div></body></html>